package com.zju.DoctorGo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zju.DoctorGo.dto.ManagerDTO;
import com.zju.DoctorGo.entity.Manager;
import com.zju.DoctorGo.mapper.ManagerMapper;
import com.zju.DoctorGo.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ManagerServiceImpl extends ServiceImpl<ManagerMapper, Manager> implements ManagerService {
    @Autowired
    private ManagerMapper managerMapper;

    @Override
    public boolean updateManagerInfo(ManagerDTO managerDTO) {
        Manager existManager = managerMapper.selectById(1L);
        Manager manager = new Manager();

        manager.setId(1L);
        manager.setUsername(managerDTO.getUsername());
        manager.setPassword(managerDTO.getPassword());
        manager.setPhone(managerDTO.getPhone());
        manager.setEmail(managerDTO.getEmail());
        manager.setBirthday(managerDTO.getBirthday());
        manager.setLocation(managerDTO.getLocation());

        int result;

        if (existManager == null) {
            result = managerMapper.insert(manager);
        } else {
            result = managerMapper.updateById(manager);
        }

        return result > 0;
    }
}
